<?php

namespace App\Http\Resources;

use App\Common\CommonConst;
use App\Models\PmFundPayment;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class PmFundPaymentResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     *
     * @todo 数据还未对齐
     *
     * @param  Request              $request
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'project_id' => $this->project_id,
            'project_name' => $this->project?->name ?? '未知',
            'sub_project_id' => $this->sub_project_id,
            'sub_project_id_name' => $this->subProject?->name ?? '未知',
            'payer' => $this->payer,
            'payee_type' => $this->payee_type,
            'payee_type_text' => PmFundPayment::$payeeTypeMap[$this->payee_type] ?? '未知',
            'period' => $this->period,
            'period_text' => $this->period == 999 ? '全款' : '第' . $this->period . '期',
            'apply_payment_amount' => $this->apply_payment_amount,
            'summary' => $this->summary,
            'is_submit_material' => $this->is_submit_material,
            'is_submit_material_text' => CommonConst::$statusMap[$this->is_submit_material] ?? '否',
            'deadline_date' => $this->deadline_date,
            'status' => $this->status,
            'created_at' => $this->created_at?->toDateTimeString(),
            'updated_at' => $this->updated_at?->toDateTimeString(),
        ];
    }
}
